package com.jiantong.web.open.app.user;

import com.jiantong.user.model.FeedBacks;
import com.jiantong.user.service.FeedBacksReadService;
import com.jiantong.user.service.FeedBacksWriteService;
import io.terminus.boot.rpc.common.annotation.RpcConsumer;
import io.terminus.common.model.Response;
import io.terminus.pampas.openplatform.annotations.OpenBean;
import io.terminus.pampas.openplatform.annotations.OpenMethod;
import io.terminus.pampas.openplatform.exceptions.OPServerException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * 意见反馈
 * Created by mz03 on 2017/3/23.
 * @author :zyp
 */
@Slf4j
@OpenBean
public class FeedBacksApis {

    @RpcConsumer
    private FeedBacksReadService feedBacksReadService ;

    @RpcConsumer
    private FeedBacksWriteService feedBacksWriteService;

    /**
     * 根据ID查询
     */
    @OpenMethod(
            key = "find.feedBacks.by.id",
            paramNames = {"id"},
            httpMethods = RequestMethod.GET
    )
    public FeedBacks findById(Long id){
        Response<FeedBacks> response = feedBacksReadService.findById(id);
        if(!response.isSuccess()){
            log.error("failed to find feedBacks read by id = {}, cause : {}", id, response.getError());
            throw new OPServerException(response.getError());
        }
        return response.getResult();

    }


    /**
     * 添加数据
     */
    @OpenMethod(
            key = "create.feedBacks",
            paramNames = {"feedBacks"},
            httpMethods = RequestMethod.POST
    )
    public Long create(FeedBacks feedBacks){
        Response<Long> response = feedBacksWriteService.create(feedBacks);
        if (!response.isSuccess()){
            log.error("failed to create feedBacks by.feedBacks = {},cause:{}",feedBacks,response.getError());
            throw new OPServerException(response.getError());
        }
        return response.getResult();
    }
}
